﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Microsoft.Office.PowerPoint.STAMP.Core
{
    /// <summary>
    /// ClosedCaptionsList contain a list of Closed Captions
    /// </summary>
    public class ClosedCaptionsSortableBindingList //: SortableBindingList<ClosedCaption>
    {
        public SortableBindingList<ClosedCaption> ClosedCaptions { get; set; }
        
        public static ClosedCaptionsSortableBindingList Empty
        {
            get { return new ClosedCaptionsSortableBindingList() { ClosedCaptions = new SortableBindingList<ClosedCaption>() }; }

        }
    } 
    /// <summary>
    /// ClosedCaptionsList contain a list of Closed Captions
    /// </summary>
    public class ClosedCaptionsList //: List<ClosedCaption>
    {
        public List<ClosedCaption> ClosedCaptions { get; set; }

        public static ClosedCaptionsList Empty
        {
            get { return new ClosedCaptionsList() {ClosedCaptions = new List<ClosedCaption>()}; }
        }

        public void MarkAsNew()
        {
            ClosedCaptions.ForEach(a => a.IsNew = true);
//            foreach (var closedCaption in ClosedCaptions)
//            {
//                closedCaption.IsNew = true;
//            }
        }
    }


    /// <summary>
    /// Class that holds the caption information from the editor and imported file
    /// </summary>
    public class ClosedCaption : ClosedCaptionBase
    {
        private string _captionText;
        private TimeSpan _endTime;
        private TimeSpan _startTime;

        internal CaptionStyle CaptionStyle { get; set; }

        internal string Id { get; set; }
        internal string MediaShapeName { get; set; }
        internal string CaptionName { get; set; }

        internal bool IsNew { get; set; }

        internal bool IsDirtyCaptionText { get; set; }
        internal bool IsDirtyStartTime { get; set; }
        internal bool IsDirtyEndTime { get; set; }

        internal bool IsDirty
        {
            get { return IsDirtyCaptionText || IsDirtyStartTime || IsDirtyEndTime; }
        }

        /// <summary>
        /// Gets or sets caption text associated with closed caption.
        /// </summary>
        public string CaptionText
        {
            get { return _captionText; }
            set
            {
                if (_captionText != value)
                {
                    IsDirtyCaptionText = true;
                    _captionText = value;
                    OnPropertyChanged("CaptionText");
                }
            }
        }

        /// <summary>
        /// Gets or sets start time associated with closed caption.
        /// </summary>
        public TimeSpan StartTime
        {
            get { return _startTime; }
            set
            {
                if (_startTime != value)
                {
                    IsDirtyStartTime = true;
                    _startTime = value;
                    OnPropertyChanged("StartTime");
                }
            }
        }

        /// <summary>
        /// Gets or sets end time associated with closed caption.
        /// </summary>
        public TimeSpan EndTime
        {
            get { return _endTime; }
            set
            {
                if (_endTime != value)
                {
                    IsDirtyEndTime = true;
                    _endTime = value;
                    OnPropertyChanged("EndTime");
                }
            }
        }
    }
}